// pages/person/registered/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    phone: '',
    code: '',
    time: '获取验证码',
    currentTime: 60,
    disabled: false,
    nickName: '',
    avatarUrl: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const {
      nickName,
      avatarUrl
    } = options
    this.setData({
      nickName: nickName,
      avatarUrl: avatarUrl
    })
  },
  bandRegister: function () {
    const {
      phone,
      code,
      avatarUrl,
      nickName
    } = this.data
    console.log(phone, code);
    if (!phone) {
      return wx.showToast({
        title: '手机号不能为空',
        icon: 'none',
        duration: 2000
      })
    } else if (!/^1[3456789]\d{9}$/.test(phone)) {
      return wx.showToast({
        title: '手机号有误',
        icon: 'none',
        duration: 2000
      })
    } else if (!code) {
      return wx.showToast({
        title: '验证码不能为空',
        icon: 'none',
        duration: 2000
      })
    } else {
      wx.navigateTo({
        url: '/pages/person/role/index?phone=' + phone + '&code=' + code + '&nickName=' + nickName + '&avatarUrl=' + avatarUrl,
      })
    }

  },
  bindPhone(e) {
    const phone = e.detail.value
    this.setData({
      phone: phone
    })
  },
  bindCode(e) {
    const code = e.detail.value
    this.setData({
      code: code
    })
  },
  bandCode() {
    const {
      phone,
    } = this.data
    if (!phone) {
      return wx.showToast({
        title: '手机号不能为空',
        icon: 'none',
        duration: 2000
      })
    } else if (!/^1[3456789]\d{9}$/.test(phone)) {
      return wx.showToast({
        title: '手机号有误',
        icon: 'none',
        duration: 2000
      })
    }
    // 发送请求获取验证码
    // this.sendCode();
    var that = this;
    var interval = '';
    var currentTime = that.data.currentTime;
    that.setData({
      time: currentTime + 's后再获取',
      disabled: true
    })
    interval = setInterval(function () {
      that.setData({
        time: (currentTime - 1) + 's后再获取'
      })
      currentTime--;
      if (currentTime <= 0) {
        clearInterval(interval)
        that.setData({
          time: '重新获取',
          currentTime: 60,
          disabled: false
        })
      }
    }, 1000)
  },
  sendCode() {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})